package com.stylefeng.guns.modular.system.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.common.constant.factory.PageFactory;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.system.model.Gdhs;
import com.stylefeng.guns.modular.system.service.IGdhsService;
import com.stylefeng.guns.modular.system.warpper.GdhsWarpper;

/**
 * 控制器
 *
 * @author fengshuonan
 * @Date 2018-05-19 10:38:35
 */
@Controller
@RequestMapping("/gdhs")
public class GdhsController extends BaseController {

    private String PREFIX = "/system/gdhs/";

    @Autowired
    private IGdhsService gdhsService;

    /**
     * 跳转到首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "gdhs.html";
    }

    /**
     * 跳转到添加
     */
    @RequestMapping("/gdhs_add")
    public String gdhsAdd() {
        return PREFIX + "gdhs_add.html";
    }

    /**
     * 跳转到修改
     */
    @RequestMapping("/gdhs_update/{gdhsId}")
    public String gdhsUpdate(@PathVariable Integer gdhsId, Model model) {
        Gdhs gdhs = gdhsService.selectById(gdhsId);
        model.addAttribute("item",gdhs);
        LogObjectHolder.me().set(gdhs);
        return PREFIX + "gdhs_edit.html";
    }

    /**
     * 获取列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(@RequestParam(required = false) String beginTime, @RequestParam(required = false) String endTime,@RequestParam(required = false) String dm,@RequestParam(required = false) Integer gtype
    		,@RequestParam(required = false) Integer qfill,@RequestParam(required = false) Integer ygsm,@RequestParam(required = false) Integer gjd
    		,@RequestParam(required = false) Integer grsm,@RequestParam(required = false) Integer jj
    		,@RequestParam(required = false) Integer qynj,@RequestParam(required = false) String name,@RequestParam(required = false) String kpd,
    		@RequestParam(required = false) Integer zjc) {
    	Page<Gdhs> page = new PageFactory<Gdhs>().defaultPage();
    	List<Map<String, Object>> gdhs = gdhsService.selectMapsByDm(page,beginTime,endTime,dm,gtype,ygsm,grsm,qfill,jj,gjd,qynj,name,kpd,zjc);
    	page.setRecords((List<Gdhs>) new GdhsWarpper(gdhs).warp());
        return super.packForBT(page);
    }

    /**
     * 新增
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Gdhs gdhs) {
        gdhsService.insert(gdhs);
        return SUCCESS_TIP;
    }

    /**
     * 删除
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer gdhsId) {
        gdhsService.deleteById(gdhsId);
        return SUCCESS_TIP;
    }

    /**
     * 修改
     */
    @RequestMapping(value = "/gdhs_update_gudong/{gdhsId}")
    public String update(@PathVariable Integer gdhsId,Model model) {
    	model.addAttribute("item",gdhsService.selectById(gdhsId));
    	return PREFIX + "gdhs_update_gudong.html";
    }
    
    /**
     * 修改
     */
    @RequestMapping(value = "/update_gudong")
    @ResponseBody
    public Object updateGudong(Integer gdhsId,String time) {
    	gdhsService.updateGudong(gdhsId,time);
    	return SUCCESS_TIP;
    }

    /**
     * 详情
     */
    @RequestMapping(value = "/detail/{gdhsId}")
    @ResponseBody
    public Object detail(@PathVariable("gdhsId") Integer gdhsId) {
        return gdhsService.selectById(gdhsId);
    }
}

